package david.java.flink_sql.udf;

import com.alibaba.fastjson.JSONValidator;
import org.apache.flink.table.functions.ScalarFunction;

/**
 * @Description: Merge jsonString, replace the former value with the latter value under the same key when the value's type is not collection
 * @Author: David
 * @Date: Create in 11:33 上午 2022/2/23
 */
public class MergeJsonString extends ScalarFunction {

    public String eval(String jsonString, String key, Object value) {
        if( null == jsonString) {
            return null;
        }
        // if (JSON.isValid())
        return  null;
    }


    public static void main(String[] args) {

        String str = "{\n" +
                "    \"load_time\":\"2022-02-21 20:39:22\",\n" +
                "    \"restriction\":{\n" +
                "        \"rule\":[\n" +
                "            {\n" +
                "                \"result_type\":8,\n" +
                "                \"result_fields\":{\n" +
                "                    \"totalPriceAmountOff\":0,\n" +
                "                    \"giftTotalStock\":0,\n" +
                "                    \"giftCount\":0,\n" +
                "                    \"repeated\":0,\n" +
                "                    \"skuPriceDiscount\":0,\n" +
                "                    \"totalPriceSet\":0,\n" +
                "                    \"giftDayStock\":0,\n" +
                "                    \"giftSkuCount\":0,\n" +
                "                    \"selectNum\":1,\n" +
                "                    \"totalPriceDiscount\":0,\n" +
                "                    \"skuPriceAmountOff\":0,\n" +
                "                    \"giftSkuId\":0,\n" +
                "                    \"skuPriceSet\":0\n" +
                "                },\n" +
                "                \"result_exp\":{\n" +
                "                    \"selectNum\":1\n" +
                "                },\n" +
                "                \"level\":1,\n" +
                "                \"condition_type\":1,\n" +
                "                \"promotion_id\":2510502,\n" +
                "                \"condition_fields\":{\n" +
                "                    \"giftSkuCount\":0,\n" +
                "                    \"skuSameWithGift\":0,\n" +
                "                    \"totalNumLimit\":0,\n" +
                "                    \"totalPriceLimit\":0.01,\n" +
                "                    \"skuCount\":0\n" +
                "                },\n" +
                "                \"condition_exp\":{\n" +
                "                    \"totalPriceLimit\":1\n" +
                "                }\n" +
                "            }\n" +
                "        ]\n" +
                "    },\n" +
                "    \"promotion_id\":\"2510502\"\n" +
                "}";
        String s1 = null;
        System.out.println(JSONValidator.from(s1).validate());

    }
}
